﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class DTgame_Bullet : MonoBehaviour
{
    public float moveSpeed;
    public UnityEvent damageEvent;
    // Start is called before the first frame update
    void Start()
    {
        Destroy(gameObject, 5f);
    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector3.right * Time.deltaTime * moveSpeed);
    }

    private void OnCollisionEnter(Collision collision)
    {
        if(damageEvent!=null)
        {
            damageEvent.Invoke();
        }

        //if(collision.gameObject.GetComponent<TDgame_TankHP>()!=null)
        //{
        //    collision.gameObject.GetComponent<TDgame_TankHP>().TakeDamage(10);
        //}

        collision.collider.SendMessageUpwards("TakeDamage", 10f, SendMessageOptions.DontRequireReceiver);
        Destroy(gameObject);
    }
}
